#!/bin/bash

set -e

PREREQ=""

prereqs()
{
    echo "${PREREQ}"
}

case "${1}" in
    prepare)
        prereqs
        exit 0
        ;;
esac

. /usr/share/initramfs-tools/hook-functions

OSTREE="/usr/bin/ostree"
if [ -x ${OSTREE} ]
then
    copy_exec ${OSTREE} /usr/sbin
	LIBC_DIR=$(ldd ${OSTREE} | sed -nr 's#.* => (/lib.*)/libc\.so\.[0-9.-]+ \(0x[[:xdigit:]]+\)$#\1#p')
	find -L "$LIBC_DIR" -maxdepth 1 -name 'libgcc_s.*' -type f | while read so; do
		copy_exec "$so"
	done
fi

CP="/usr/bin/cp"
if [ -x ${CP} ]
then
    copy_exec ${CP} /usr/sbin
	LIBC_DIR=$(ldd ${CP} | sed -nr 's#.* => (/lib.*)/libc\.so\.[0-9.-]+ \(0x[[:xdigit:]]+\)$#\1#p')
	find -L "$LIBC_DIR" -maxdepth 1 -name 'libgcc_s.*' -type f | while read so; do
		copy_exec "$so"
	done
fi
